/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 *
 * @Original Author: jin Chen
 * @date: Apr 15, 2004$
 * @version: 1.0
 */
package edu.psu.geovista.app.dataloader.v1.actions;

import edu.psu.geovista.app.dataloader.v1.config.model.ModelUtils;
import edu.psu.geovista.app.dataloader.v1.config.model.Pcpdata;
import edu.psu.geovista.app.dataloader.v1.config.model.Project;
import edu.psu.geovista.app.dataloader.v1.session.ProjectBuilder;

import java.util.Hashtable;

public class WizardData {
    int projectCategory=New ;//New , Existing, Current,
    //boolean loadPcpdata;
    //boolean loadTsdata;
    public static final int New=1;
    public static final int Exist=2;
    public static final int Current=3;

    private Project project;

    public void clean() {
        this.project =null;
        projectCategory=New ;
    }
    public void setProjectName(String pn) {
        this.getProject().setID(pn);
    }
    public int getProjectCategory() {
        return projectCategory;
    }
    public void setProjectCategory(int projectCategory) {
        this.projectCategory = projectCategory;
    }

    public boolean isLoadPcpdata() {
        return project.getPcpdata().isLoad();
    }

    public void setLoadPcpdata(boolean loadPcpdata) {
        this.project.getPcpdata().setLoad(loadPcpdata);
    }

    public boolean isLoadTsdata() {
        return project.getTsdata().isLoad();
    }

    public void setLoadTsdata(boolean loadTsdata) {
        this.project.getTsdata().setLoad(loadTsdata);
    }

    public void setProjectedData(boolean projected) {
        this.project.getPcpdata().setShapeProjected(projected);
    }
    public boolean isProjectedData() {
        return  this.project.getPcpdata().isShapeProjected() ;
    }

    public void setPcpPaths(Hashtable paths) {
         ModelUtils.setPaths(this.project.getPcpdata(),paths);
    }
    public void setTsPaths(Hashtable paths) {
         ModelUtils.setPaths(this.project.getTsdata(),paths);
    }
    public void selectPcpAttrs(String [] attrs) {
        ModelUtils.setSelectAttributeNames(this.project.getPcpdata(),attrs);
    }
    public void selectTsAttrs(String [] attrs) {
        ModelUtils.setSelectAttributeNames(this.project.getTsdata(),attrs);
    }
    // 
    public Project getProjectClone() {

        Project proj=this.getProject() ;
        Project tmp=getBrandNewProject();
        ModelUtils.copyObject(proj,tmp);
        return tmp;
    }
    /**
     *
     * @return ID of current project
     */
    public String getProjectID(){
        return this.getProject().getID() ;
    }
    /**
     * Don't make it public, user getProjectClone() instead
     * @return
     */
    private Project getProject(){
         if(project==null){
            project=getBrandNewProject();//ConfigureProcessor.getProjectInstance();
            project.setID(ProjectBuilder.Project_New);
             Pcpdata pcpdata = project.getPcpdata();
             pcpdata.setLoad(true);
            project.getTsdata().setLoad(true);
        }
        return project;
    }
    private  Project getBrandNewProject() {
        return ModelUtils.getProjectInstance();
    }

    /**
     * copy projects
     * @param project
     */
    public void setProject(Project project) throws IllegalArgumentException {
        if(project==null){

             throw  new IllegalArgumentException("No project information is found");

        }
        else    {
            ModelUtils.copyObject(project,this.getProject());
        }
       // System.out.println(""+this.project );

        //this.project = project;
    }

    public boolean hasProject(Project proj){
        if(project!=null&&proj!=null&&project.getID().equals(proj.getID())){
            return true;
        }
        else{
            return false;
        }
    }

     public boolean hasProject(String name){
        if(project!=null&&project.getID().equals(name)){
            return true;
        }
        else{
            return false;
        }
    }

}
